#include <standard.hlsli>

struct VS_INPUT2
{
	float4 Position : POSITION0;
	float2 Texcoord : TEXCOORD0;
	float3 Normal   : NORMAL0;
};

struct VS_INPUT_INST
{
	float4 Position :INSTANCE1;
	float4 mx       :INSTANCE2;
	float4 my       :INSTANCE3;
	float4 mz       :INSTANCE4;
	float4 mw       :INSTANCE5;
	float scale : INSTANCE6;
};

struct VS_OUTPUT
{
	float4 Position : SV_POSITION0;
	float2 Texcoord : TEXCOORD1;
	float3 Normal   : TEXCOORD0;
};

VS_OUTPUT vs_main(VS_INPUT2 Input, VS_INPUT_INST Inst)
{
	VS_OUTPUT Output = (VS_OUTPUT)0;
	Input.Position.w = 1.0f;
	float4x4 instanceMatrix = float4x4(Inst.mx, Inst.my, Inst.mz, Inst.mw);
		Input.Position.xyzw = mul(Input.Position.xyzw, Inst.scale);
	Input.Position = mul(Input.Position, instanceMatrix);
	float4 posi = mul(Inst.Position, 2.0f);
		posi.xyz = Input.Position.xyz + posi.xyz;
	Output.Position = mul(posi, worldViewProj);
	Output.Normal = float3(normalize(mul(Input.Normal, (float3x3)instanceMatrix)));
	Output.Texcoord = Input.Texcoord;

	return(Output);
}